{include file="public/toper" /}
<div class="layui-tab-brief main-tab-container">
    <ul class="layui-tab-title main-tab-title">
        <li class="layui-this"><a href="{:url('edit',array('id'=>$data['id']))}">单页编辑</a></li>
        <span class="main-tab-item">单页管理</span>
    </ul>
    <div class="layui-tab-content">
        <form class="layui-form">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属栏目</label>
                    <div class="layui-input-inline input-custom-width select-parent-id">
                        <select name="category_id" lay-verify="required" disabled>
                            <option value=""></option>
                            {$category_select}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input" value="{$data.title|default=''}">
                        <input type="hidden" name="id" required lay-verify="required"
                               autocomplete="off" class="layui-input" value="{$data.id|default=0}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="text" name="image_url" value="{$data.image_url|default=''}" placeholder=""
                               class="layui-input">
                        <button type="button" class="layui-btn layui-upload-button" id="image">
                            <i class="layui-icon layui-icon-upload-drag"></i>图片
                        </button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">关键词</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="text" name="keywords" autocomplete="off" class="layui-input"
                               value="{$data.keywords|default=''}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">关键词以英文逗号隔开</div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">摘要</label>
                    <div class="layui-input-inline input-custom-width">
                        <textarea name="description" class="layui-textarea">{$data.description|default=''}</textarea>
                    </div>
                    <div class="layui-form-mid layui-word-aux">留空时默认截取内容的前250个字符</div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        {if condition="$setting['edit_type'] eq '1'"}
                            <textarea name="content" lay-verify="layedit" autocomplete="off" placeholder="请输入内容"
                                  class="layui-textarea layui-hide" id="edit">{$data['content']|default=''}</textarea>
                        {elseif condition="$setting['edit_type'] eq '2'" /}
                            {:Lemon_get_umeditior(htmlspecialchars_decode($data['content']|default=''))}
                        {elseif condition="$setting['edit_type'] eq '3'" /}
                            {:Lemon_get_wangEditor(htmlspecialchars_decode($data['content']|default=''))}
                        {/if}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">添加时间</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="text" name="create_time" value="{$data.create_time|default=date('Y-m-d H:i:s',time())}" id="date"
                               lay-verify="datetime" placeholder="YYYY-MM-DD hh:mm:ss" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">默认是当前时间</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">点击量</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="number" name="hits" value="{$data.hits|default=0}"  autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接地址</label>
                    <div class="layui-input-inline input-custom-width">
                        <input type="text" name="url" autocomplete="off" class="layui-input" value="{$data.url|default=''}">
                        {:token()}
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="cate_add">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</div>
<script type="text/javascript">
    layui.use(['element', 'form', 'upload', 'layedit' ,'laydate'], function () {
        var element = layui.element
            , form = layui.form
            , jq = layui.$
            , layedit = layui.layedit
            ,laydate = layui.laydate;
        var upload = layui.upload;
        jq('input[name=image_url]').hover(function () {
            jq(this).after('<img class="input-img-show" src="' + jq(this).val() + '" >');
        }, function () {
            jq(this).next('img').remove();
        });
        //创建一个编辑器
        layedit.set({
            uploadImage: {
                url: "{:url('upload/layedit_upimage')}" //接口url
                , type: 'post' //默认post
            }
        });
        var _edit = layedit.build('edit');
        //表单验证
        form.verify({
            //编辑器数据同步
            layedit: function (value) {
                layedit.sync(_edit);
            }
        });


        laydate.render({
            elem: '#date' //指定元素
            ,type: 'datetime'
        });
        //图片上传
        var up = upload.render({
            url: "{:url('upload/upimage')}"
            , elem: '#image'
            , size: "{$Think.POST_MAX *1024}"
            , before: function (input) {
                loading = layer.load(2, {
                    shade: [0.2, '#000'] //0.2透明度的白色背景
                });
            }
            , done: function (res) {
                layer.close(loading);
                jq('input[name=image_url]').val(res.path);
                layer.msg(res.msg, {icon: 1, time: 1000});
            }, error: function () {
                layer.close(loading);
                layer.msg('上传失败');
            }
        });
        //监听提交
        form.on('submit(cate_add)', function (data) {
            loading = layer.load(2, {
                shade: [0.2, '#000'] //0.2透明度的白色背景
            });
            var param = data.field;
            jq.post(
                '{:url("addPost")}',
                param,
                function (data) {
                    if (data.code == 200) {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            location.reload();//do something
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                    }
                }).error(function () {
                layer.close(loading);
                layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
            });
            return false;
        });

    })
</script>
</body>
</html>

